package cn.waka.sys.admin.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.waka.sys.admin.dao.DicDao;
import cn.waka.sys.admin.object.Dic;

@Service
public class DicService {
	
	private DicDao dao;
	
	@Autowired
	public void setDao(DicDao dao){
		this.dao=dao;
	}
	
	public List<Map<String,Object>> getTypeList(String pid){	
		int id = Integer.valueOf(pid);
		return dao.getTypeList(id);
	}
	public List<Map<String,Object>> getDicList(String pid){	
		int id = Integer.valueOf(pid);
		return dao.getDicList(id);
	}
	
	public List<Map<String,Object>> getDicByKey(String key){	
		return dao.getDicByKey(key);
	}
	
	
	//禁用/启用
	public int isDisable(int id,int status) {
		return dao.isDisable(id, status);
	}
	
	//根据ID删除字典
	public int deleteDic(int id) {
		return dao.delDicTree(id);
	}
	
	public List<Dic> getDicByPid(int pid){	
		return dao.getDicByPid(pid);
	}
	
	public List<Dic> getDicMenu(int pid,int id){	
		return dao.getDicMenu(pid,id);
	}
	
	public Dic getDicById(int id){	
		return dao.getDicById(id);
	}
	
	public int saveDic(Dic r){
		int rs = 1;
		Dic p_dic = dao.getDicById(r.getPid());
		String key = p_dic.getKey();
		if(r.getId()>0){
			key = key+","+r.getId();
			r.setKey(key);
			rs = dao.updateDIc(r);
		}else{
			rs = dao.insert(r);
			key = key+","+rs;
			dao.updateKey(rs,key);
		}
		return rs;
	}
	
	public Map<Integer,String> getDicMap(){	
		return dao.getDicMap();
	}
}
